package com.spirng.leetcode.day01;

public class Array3_1 {
    public static void main(String[] args) {
        removeDuplicates(new int[]{1,1,2});
    }
    public static int removeDuplicates(int[] nums) {
     int slowIndex=0;
     for (int fastIndex=1;fastIndex< nums.length;fastIndex++){
         if(nums[slowIndex]!= nums[fastIndex]) {
             nums[++slowIndex]=nums[fastIndex];
         }

     }
     return slowIndex+1;
    }
    public static int removeElement(int[] nums, int val) {
        int left = 0;
        int right = nums.length - 1;
        while(left <= right){
            if(nums[left] == val){
                nums[left] = nums[right];
                right--;
            }else {
                // 这里兼容了right指针指向的值与val相等的情况
                left++;
            }
        }
        return left;
    }
}
